GlobalTools : Sử dụng các hàm trong đây như các hàm sẳn  của VB6 !

 

1.     Một số hàm cần dùng

 

ColorsBlend(Color1 As Long, Color2 As Long, Optional PercentInDecimal As Single = 0.5) As Long

Hàm này dùng để trộn hai màu lại với nhau. PercentInDecimal giống như là liều lượng của hai màu vậy.Ví dụ :

    ColorsBlend(Đỏ,Đen,0.3) => Màu đỏ chỉ có 0.3 c̣n màu đen là 0.7

ShowCustomColor(Optional ByVal Defaultcolor As OLE_COLOR) As OLE_COLOR

Show bảng chọn màu. Trả về giá trị màu mà bạn chọn.

Defaultcolor : Màu của bạn hiện tại

IsMouseButton() As Integer

Hàm trả về nút chuột đang nhấn (1 = chuột trái,2 = phải, 4 = chuột giữa)

IsShiftState() As Integer

Hàm trả về 1 nếu phím Shift đang được giử (Hold).

IsKeyPress(ByVal vKeyCode As KeyCodeConstants) As Boolean

Hàm trả về True nếu vKeycode được press. Ngược lại False

DeleteRegeditKey(ByVal KeyRoot As T_KeyClasses, ByVal PathStr As String, ByVal sKey As String)

Xóa Key trong Registry.Chắc bạn nh́n cũng hiểu rồi (^_^)

SaveRegeditKey(ByVal KeyRoot As T_KeyClasses, ByVal sPath As String) As Long

Lưu lại một Key trong Registry

SaveRegeditValue(ByVal KeyRoot As T_KeyClasses, ByVal PathStr As String, ByVal sKey As String, ByVal sREG As RegValue, ByVal NewValue As String)

Lưu lại giá trị vào Value,sREG là kiểu dử liệu mà bạn ghi vào (BINARY,DWORD,STRING),các biến c̣n lại th́ giống như hàm trên

RegisterFont (ByVal FontFileName As String, ByVal Question As Integer)

     Đăng ký Font với hệ thống (Windows)

     FontFileName là đường dẩn của Font,Question = 0 là  Đăng ký và Question = 1 là gở khỏi hệ thống.

TranparenthWnd(lHWnd As Long, iAlpha As Integer)

Làm cho Form trong suốt.lhWnd là Handle của Form mà bạn cần làm trong suốt.iAlpha là giá trị trong suốt (Độ trong suốt)

FileExist(FileAddress As String) As Boolean

Kiểm tra xem file tồn tại không.Giá trị trả vềdạng Boolean

Nếu False th́ file không tồn tại ngược lại.

PressKey (ByVal bKey As Byte, Optional ByVal bShift As Byte = 0)

Giả lập nhấn phím, gần giống như sendkeys vậy.

Các Key tham khảo :

 

   VK_LWIN = &H5B 'Left Windows key (Microsoft® Natural® keyboard)

   VK_RWIN = &H5C 'Right Windows key (Natural keyboard)

   VK_APPS = &H5D 'Applications key (Natural keyboard)

   VK_SLEEP = &H5F 'Computer Sleep key

  

   VK_RMENU = &HA5 ' Right MENU key

   VK_BROWSER_BACK = &HA6 'Windows 2000/XP: Browser Back key

   VK_BROWSER_FORWARD = &HA7 'Windows 2000/XP: Browser Forward key

   VK_BROWSER_REFRESH = &HA8 'Windows 2000/XP: Browser Refresh key

   VK_BROWSER_STOP = &HA9 'Windows 2000/XP: Browser Stop key

   VK_BROWSER_SEARCH = &HAA 'Windows 2000/XP: Browser Search key

   VK_BROWSER_FAVORITES = &HAB 'Windows 2000/XP: Browser Favorites key

   VK_BROWSER_HOME = &HAC 'Windows 2000/XP: Browser Start and Home key

   VK_VOLUME_MUTE = &HAD 'Windows 2000/XP: Volume Mute key

   VK_VOLUME_DOWN = &HAE  'Windows 2000/XP: Volume Down key

   VK_VOLUME_UP = &HAF  'Windows 2000/XP: Volume Up key

   VK_MEDIA_NEXT_TRACK = &HB0  'Windows 2000/XP: Next Track key

   VK_MEDIA_PREV_TRACK = &HB1  'Windows 2000/XP: Previous Track key

   VK_MEDIA_STOP = &HB2  'Windows 2000/XP: Stop Media key

   VK_MEDIA_PLAY_PAUSE = &HB3  'Windows 2000/XP: Play/Pause Media key

   VK_LAUNCH_MAIL = &HB4  'Windows 2000/XP: Start Mail key

   VK_LAUNCH_MEDIA_SELECT = &HB5  'Windows 2000/XP: Select Media key

   VK_LAUNCH_APP1 = &HB6  'Windows 2000/XP: Start Application 1 key

   VK_LAUNCH_APP2 = &HB7  'Windows 2000/XP: Start Application 2 key

   VK_OEM_1 = &HBA 'Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ';:' key

 

   VK_OEM_PLUS = &HBB 'Windows 2000/XP: For any country/region, the '+' key

   VK_OEM_COMMA = &HBC 'Windows 2000/XP: For any country/region, the ',' key

   VK_OEM_MINUS = &HBD 'Windows 2000/XP: For any country/region, the '-' key

   VK_OEM_PERIOD = &HBE 'Windows 2000/XP: For any country/region, the '.' key

   VK_OEM_2 = &HBF 'Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '/?' key

   VK_OEM_3 = &HC0 'Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '`~' key

 

'—  C1–D7 Reserved

'—  D8–DA Unassigned

   VK_OEM_4 = &HDB 'Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '[{' key

   VK_OEM_5 = &HDC 'Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '\|' key

   VK_OEM_6 = &HDD 'Used for miscellaneous characters; it can vary by keyboard Windows 2000/XP: For the US standard keyboard, the ']}' key

   VK_OEM_7 = &HDE ' Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the 'single-quote/double-quote' key

   VK_OEM_8 = &HDF 'Used for miscellaneous characters; it can vary by keyboard. —  E0 Reserved

'- E1 OEM specific

   VK_OEM_102 = &HE2 'Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard

' E3–E4 OEM specific

   VK_PROCESSKEY = &HE5 'Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key

' E6 OEM specific

   VK_PACKET = &HE7 'Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP

'—  E8 Unassigned

' E9–F5 OEM specific

   VK_ATTN = &HF6 'Attn key

   VK_CRSEL = &HF7 'CrSel key

   VK_EXSEL = &HF8 'ExSel key

   VK_EREOF = &HF9 'Erase EOF key

   VK_PLAY = &HFA 'Play key

   VK_ZOOM = &HFB 'Zoom key

   VK_NONAME = &HFC 'Reserved for future use

   VK_PA1 = &HFD 'PA1 key

   VK_OEM_CLEAR = &HFE 'Clear key


2.         Hàm về chuỗi

 

UnicodeInputBox(ByVal Prompt As String, Optional ByVal Default = "", Optional ByVal Title = "", Optional XPos As Single = 1, Optional YPos As Single = 1) As String

Giống như Inputbox của VB6 nhưng nó có unicode

StringToByte(ByVal sString As String) As Byte()

Chuyễn một chuỗi sang dạng Byte() [Array Byte].

UnicodeMsgBox(sPrompt As String, Optional iButtons As VbMsgBoxStyle = vbOKOnly, Optional sTitle As String) As VbMsgBoxResult

Giống như Msgbox của VB6 nhưng có unicode,cách sử dụng không khác ǵ Msgbox

UnicodeTelex(xStr As String) As String

Chuyễn một chuỗi dạng telex sang unicode ,ví dụ : Tieesng vieejt = "Tiếng việt"

UnicodeText(xStr As String) As String

Chuyễn một chuỗi dạng Vni sang unicode , Ví dụ : Tie61ng vie65t = "Tiếng việt"

UTF8ToUni(ByVal sUTF8 As String) As String

Chuyễn một chuỗi từ UTF8 sang unicode

UniToUTF8(ByVal sUni As String) As String

Chuyễn một chuỗi từ Unicode sang UTF8

UnicodeTCVN3(xStr As String) As String

Chuyễn một chuỗi dạng ABC sang unicode , Ví dụ : TiƠng ViÖt = "Tiếng việt”

ConvString(srcString As String, DesType As ConvStr, ConvType As ConvStr) As String

Đây là hàm chuyễn chuỗi.Chuyễn qua lại giữa các dạng VNI, ABC, UTF8, Unicode.

scrString là chuỗi mà bạn cần chuyễn.DesType là dạng ban đầu của chuỗi,ConvType là dạng mà bạn muốn chuyễn thành.Nó sẽ trả về giá trị mà bạn muốn chuyễn thành

PtrStr(Ptr As Long) As String

Lấy chuỗi trong giá trị Long khi dùng hàm StrPtr(Str)

dụ :

Dim m_Str As Long

m_Str = StrPtr(“Chuỗi”)

Me.Caption = PtrStr(m_Str) => Caption = “Chuỗi

UnicodeToHexaDecimal(ByVal UnicodeString As String) As String

Chuyễn 1 chuỗi dạng unicode sang ASCII.

HexaDecimalToUnicode(ByVal Character As String) As String

Chuyễn 1 chuỗi dạng ASCII code sang unicode.